<div class="layuimini-main">
    <div class="layui-hide args"> {{args}}</div>
    <div class="layui-form layuimini-form">
        <div class="layui-form-item">
            <label class="layui-form-label required">上下文长度</label>
            <div class="layui-input-block">
                <input type="number" name="ctx_len" lay-verify="required" lay-reqtext="上下文长度不能为空"
                       placeholder="请输入上下文长度 512"
                       value="" class="layui-input">
                <tip>填写训练数据时的上下文长度。</tip>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label required">训练轮数</label>
            <div class="layui-input-block">
                <input type="number" name="n_epoch" lay-verify="required" lay-reqtext="训练轮数不能为空"
                       placeholder="请输入训练轮数 100"
                       value="" class="layui-input">
                <tip>填写训练数据时的训练轮数。</tip>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label required">批训练条数</label>
            <div class="layui-input-block">
                <input type="number" name="batch_size" lay-verify="required" lay-reqtext="批训练条数不能为空 10"
                       placeholder="请输入批训练条数"
                       value="" class="layui-input">
                <tip>填写训练数据时的批训练条数。</tip>
            </div>
        </div>
        <!--        <div class="layui-form-item">-->
        <!--            <label class="layui-form-label required">语境库Lable-id</label>-->
        <!--            <div class="layui-input-block">-->
        <!--                <input type="text" name="label_id" lay-verify="required" lay-reqtext="语境库Lable-id不能为空"-->
        <!--                       placeholder="标记码"-->
        <!--                       value="" class="layui-input">-->
        <!--                <tip>该语境库Lable-id用于关联图书馆</tip>-->
        <!--            </div>-->
        <!--        </div>-->
        <div class="layui-form-item">
            <label class="layui-form-label">初始化加载</label>
            <div class="layui-input-block">
                <input type="checkbox" name="init_load" value="1" lay-skin="switch" lay-filter="switchTest"
                       lay-text="ON|OFF">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label required">语境库名称</label>
            <div class="layui-input-block">
                <input type="text" name="con_name" lay-verify="required" lay-reqtext="语境库名称不能为空"
                       placeholder="语境库名称"
                       value="" class="layui-input">
                <tip>语境库名称</tip>
            </div>
        </div>
        <!-- <div class="layui-form-item layui-form-text">
             <label class="layui-form-label">关联语境库</label>
             <div class="layui-input-block">
                 <select name="label_id" class="labelId">
                     <option value="" class="option">请选择</option>
                 </select>
             </div>
         </div>-->
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">备注信息</label>
            <div class="layui-input-block">
                <textarea name="remark" class="layui-textarea" placeholder="请输入备注信息"></textarea>
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
            </div>
        </div>
    </div>
</div>
<script>
    layui.use(['form', 'table'], function () {
        var form = layui.form,
            layer = layui.layer,
            table = layui.table,
            $ = layui.$;

        let args = JSON.parse($('.args').html())
        let init_load = 0

        $.get('/admin/modules/' + args.id, function (res) {
            if (res.code === 0) {
                let module = res.data
                $("[name='ctx_len']").val(module.ctx_len)
                $("[name='n_epoch']").val(module.n_epoch)
                $("[name='batch_size']").val(module.batch_size)
                $("[name='remark']").val(module.remark)
                $("[name='label_id']").val(module.module_code)
                $("[name='con_name']").val(module.con_name)
                if (module.init_load && module.init_load === 1) {
                    $('[name="init_load"]').attr('checked', 'checked');
                    form.render();
                }
            }
        })

        //监听指定开关
        form.on('switch(switchTest)', function (data) {
            init_load = this.checked ? 1 : 0
        });


        /**
         * 初始化表单，要加上，不然刷新部分组件可能会不加载
         */
        form.render();

        // 当前弹出层，防止ID被覆盖
        var parentIndex = layer.index;

        //监听提交
        form.on('submit(saveBtn)', function (data) {
            // console.log(data)
            // console.log(args.id)
            data.field['init_load'] = init_load

            $.post(
                '/admin/modules/update/' + args.id,
                data.field,
                function (res) {
                    console.log(res)
                    layer.close(parentIndex);
                }, 'json')
            // var index = layer.alert(JSON.stringify(data.field), {
            //     title: '最终的提交信息'
            // }, function () {
            //
            //     // 关闭弹出层
            //     layer.close(index);
            //     layer.close(parentIndex);
            //
            // });


            return false;
        });

    });
</script>